Object.defineProperty(exports, "__esModule", {
  value: true
});
var LogManager = require("AA_LogManager");
var ResLoader = require("AA_ResLoader");
var ResUtil = require("AA_ResUtil");
var _def_UITools = function () {
  function _creator() {}
  _creator.addClickEvent = function (e, t, o, i) {
    undefined === i && (i = 500);
    if (null == e ? undefined : e.node) {
      e.node.off("click");
      e.node.on("click", function (n) {
        if (i > 0) {
          var a = e.lastclickTime;
          if (a) {
            if (new Date().getTime() - a < i) {
              return;
            }
            e.lastclickTime = new Date().getTime();
            t.apply(o, [n]);
          } else {
            e.lastclickTime = new Date().getTime();
            t.apply(o, [n]);
          }
        } else {
          t.apply(o, [n]);
        }
      }, o);
    } else {
      LogManager.LogMgr.error("add click event error: " + e);
    }
  };
  _creator.rmClickEvent = function (e) {
    if (null == e ? undefined : e.node) {
      e.node.off("click");
    } else {
      LogManager.LogMgr.error("remove click event error: " + e);
    }
  };
  _creator.shake = function (e, t) {
    var o = cc.tween(e);
    var n = [{
      position: cc.v2(t.x, t.y),
      duration: .05
    }, {
      position: cc.v2(-t.x, -t.y),
      duration: .05
    }, {
      position: cc.v2(t.x, t.y),
      duration: .05
    }, {
      position: cc.v2(-t.x, -t.y),
      duration: .05
    }, {
      position: cc.v2(0, 0),
      duration: .05
    }];
    o.by(0, {
      position: cc.v3(0, 0)
    });
    var i = 0;
    for (var a = n; i < a.length; i++) {
      var r = a[i];
      o.by(r.duration, {
        position: cc.v3(r.position)
      });
    }
    o.start();
  };
  _creator.loadTexture = function (e, t, o) {
    ResLoader.default.loadRes(t, o, cc.SpriteFrame).then(function (t) {
      if (t) {
        e.spriteFrame = t;
        ResUtil.ResUtil.assignWith(t, e.node);
      }
    });
  };
  _creator.loadDragonBones = function (e, t, o) {
    return new Promise(function (n, r) {
      var c = cc.path.basename(o);
      var s = cc.path.dirname(o);
      var u = s + "/" + c + "_ske";
      var l = s + "/" + c + "_tex";
      ResLoader.default.loadRes(t, u, dragonBones.DragonBonesAsset).then(function (o) {
        if (o) {
          ResUtil.ResUtil.assignWith(o, e.node);
          ResLoader.default.loadRes(t, l, dragonBones.DragonBonesAtlasAsset).then(function (t) {
            if (t) {
              e.dragonAsset = o;
              e.dragonAtlasAsset = t;
              ResUtil.ResUtil.assignWith(o, e.node);
              n(true);
            } else {
              r(false);
            }
          });
        } else {
          r(false);
        }
      });
    });
  };
  _creator.addTouchEventListener = function (e, t, o) {
    e.on(cc.Node.EventType.TOUCH_START, t, o);
    e.on(cc.Node.EventType.TOUCH_MOVE, t, o);
    e.on(cc.Node.EventType.TOUCH_END, t, o);
    e.on(cc.Node.EventType.TOUCH_CANCEL, t, o);
  };
  _creator.rmTouchEventListener = function (e) {
    e.off(cc.Node.EventType.TOUCH_START);
    e.off(cc.Node.EventType.TOUCH_MOVE);
    e.off(cc.Node.EventType.TOUCH_END);
    e.off(cc.Node.EventType.TOUCH_CANCEL);
  };
  _creator.fadeOut = function (e, t, o, n) {
    undefined === o && (o = false);
    undefined === n && (n = true);
    cc.Tween.stopAllByTarget(e);
    cc.tween(e).to(t, {
      opacity: 0
    }).call(function () {
      o && ResUtil.ResUtil.removeFromParent(e, n);
    }).start();
  };
  _creator.scaleTo = function (e, t) {
    var o = t / Math.max(e.width, e.height);
    e.scale = o;
  };
  return _creator;
}();
exports.default = _def_UITools;